<?php

/**
 * product actions.
 *
 * @package    fkshop
 * @subpackage product
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class productActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
  	
  	 $this->categories = Doctrine_Core::getTable('Category')->getWithProducts();
//     $this->products = Doctrine_Core::getTable('Product')->getProducts();
 //    $this->randomProducts = Doctrine_Core::getTable('Product')->getProductByRandom();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->product = $this->getRoute()->getObject();
    $this->getUser()->addProductToHistory($this->product);
    
  }

  public function executeSearch(sfWebRequest $request){
  	$this->keywords = $request->getParameter('keywords');
  	$this->results = Doctrine_Core::getTable('Product')->getProductsByName($this->keywords);
  	
  }
  
  public function executeRandomProducts(sfWebRequest $request){
  	
  }
  
  public function executeAddToCart(sfWebRequest $request)
  {
  	$this->quantity = $request->getParameter('txtQte');
  	$this->idProduit = $request->getParameter('idPrd');  		
  	$this->produit = Doctrine_Core::getTable('Product')->getProductById($this->idProduit);
  	
  	
  	$this->getUser()->addProductToCart($this->idProduit, $this->quantity);
  	$this->forward("product", "index");
  }

}
